/*
 * @lc app=leetcode.cn id=28 lang=java
 *
 * [28] 实现 strStr()
 */

// @lc code=start
class Solution {
    public int strStr(String haystack, String needle) {
        if(needle == null || needle.equals(""))
            return 0;
        for(int i = 0;i<haystack.length();i++){
            if(haystack.charAt(i)==needle.charAt(0)){
                for(int j = i ,k=0 ;j<haystack.length() && k<needle.length();k++,j++){
                    if(haystack.charAt(j)!=needle.charAt(k))
                        break;
                }
                if(k == needle.length) return i;
            }
        }
        return -1;
    }
}
// @lc code=end

